package org.xg.study.hin.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName HibernateUtils
 * @date 2021/9/26 10:44
 **/
public class HibernateUtils {
    private static final Configuration CONFIGURATION;
    private static final SessionFactory SESSION_FACTORY;

    /**
     * 在静态代码块中创建SessionFactory对象
     */
    static {
        CONFIGURATION = new Configuration().configure();
        SESSION_FACTORY = CONFIGURATION.buildSessionFactory();
    }

    /**
     * 通过SessionFactory对象创建Session对象
     * @return
     */
    public static Session getSession(){
        return SESSION_FACTORY.openSession();
    }
}
